/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gblend.similarity;

import gblend.adjlistgraph.FsgIdEntry;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Vector;

/**
 *
 * @author cjjin
 */
public class IdSort implements Comparator {

    public int compare(Object o1, Object o2) {
        if (o1 instanceof FsgIdEntry) {
            FsgIdEntry e1 = (FsgIdEntry) o1;
            FsgIdEntry e2 = (FsgIdEntry) o2;
            Vector<Integer> e1l = e1.getGraphId();
            Vector<Integer> e2l = e2.getGraphId();
            if (e1l.size() > e2l.size()) {
                return 1;
            } else if (e1l.size() < e2l.size()) {
                return -1;
            } else {
                Iterator<Integer> e1li = e1l.iterator();
                Iterator<Integer> e2li = e2l.iterator();
                while (e1li.hasNext()) {
                    int e1int = e1li.next();
                    int e2int = e2li.next();
                    if (e1int > e2int) {
                        return 1;
                    } else if (e2int > e1int) {
                        return -1;
                    }
                }
                return 0;
            }
        } else {
            int e1 = (Integer) o1;
            int e2 = (Integer) o2;
            if (e1 > e2) {
                return 1;
            } else if (e1 == e2) {
                return 0;
            } else {
                return -1;
            }
        }
    }
}
